package com.gxs.ea.fileportal.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Field {
	
	public static final String FIELD_TYPE_STRING = "String";
	public static final String FIELD_TYPE_INTEGER = "Integer";
	public static final String FIELD_TYPE_FLOAT = "Float";
	public static final String FIELD_TYPE_BOOLEAN = "Boolean";
	public static final String FIELD_TYPE_DATE = "Date";
	public static final String FIELD_TYPE_TIMESTAMP = "Timestamp";
	public static final String FIELD_TYPE_LISTOFVALUE = "ListOfValues";
	
	public static final String FIELD_SOURCE_USER_ENTERED ="User Provided";
	public static final String FIELD_SOURCE_USER_ENTERED_LOV ="User Provided From List of Values";
	public static final String FIELD_SOURCE_AUTO = "Auto Populated";
	public static final String FIELD_SOURCE_EXTRACTED ="Extract from Data";
	
	public static final String AUTO_OPTIONS_CURRENT_USER = "Current User";
	public static final String AUTO_OPTIONS_CURRENT_DATE = "Current Date";
	public static final String AUTO_OPTIONS_CURRENT_TIMESTAMP = "Current Timestamp";
	public static final String AUTO_OPTIONS_COMPANY_CODE = "Company Code";
	public static final String AUTO_OPTIONS_ORIGINAL_FILENAME = "Original File Name";
	
	public static final String  DEFAULT_FIELD_GROUPING = "Reference Info";
	
	private static List<String> listOfAllTypes = new ArrayList<String>();
	private static List<String> listOfAllSources = new ArrayList<String>();
	private static List<String> listOfAllAutoOptions = new ArrayList<String>();

	static
	{
		listOfAllTypes.add(FIELD_TYPE_STRING);
		listOfAllTypes.add(FIELD_TYPE_INTEGER);
		listOfAllTypes.add(FIELD_TYPE_FLOAT);
		listOfAllTypes.add(FIELD_TYPE_BOOLEAN);
		listOfAllTypes.add(FIELD_TYPE_DATE);
		listOfAllTypes.add(FIELD_TYPE_TIMESTAMP);

		listOfAllSources.add(FIELD_SOURCE_USER_ENTERED);
		listOfAllSources.add(FIELD_SOURCE_USER_ENTERED_LOV);
		listOfAllSources.add(FIELD_SOURCE_AUTO);
		listOfAllSources.add(FIELD_SOURCE_EXTRACTED);
		
		listOfAllAutoOptions.add(AUTO_OPTIONS_CURRENT_USER);
		listOfAllAutoOptions.add(AUTO_OPTIONS_CURRENT_DATE);
		listOfAllAutoOptions.add(AUTO_OPTIONS_CURRENT_TIMESTAMP);
		listOfAllAutoOptions.add(AUTO_OPTIONS_COMPANY_CODE);
		listOfAllAutoOptions.add(AUTO_OPTIONS_ORIGINAL_FILENAME);

	}
	
	private String fieldName;
	private String fieldDisplayName;
	private String fieldHelpText;
	private String fieldGrouping;
	private String  fieldType;
	private String fieldSource;
	private String fieldAutoOptionSelected;
	private String fieldExtractedDataPath;
	private Map<String,String> fieldListOfValueOptions = new LinkedHashMap<String,String>();
	private boolean required = false;
	private boolean showInSummaryTable = false;
	private boolean showInDetailsPane = true;
	private String tempListOfValuesDelimited = null;
	private boolean searchable = false;
	private boolean filterable = false;
	private boolean sortable = false;
	private String inputMask;
	
	public String getFieldName() {
		return fieldName;
	}
	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}
	public String getFieldDisplayName() {
		return fieldDisplayName;
	}
	public void setFieldDisplayName(String fieldDisplayName) {
		this.fieldDisplayName = fieldDisplayName;
	}
	public String getFieldHelpText() {
		return fieldHelpText;
	}
	public void setFieldHelpText(String fieldHelpText) {
		this.fieldHelpText = fieldHelpText;
	}
	public String getFieldGrouping() {
		return fieldGrouping;
	}
	public void setFieldGrouping(String fieldGrouping) {
		this.fieldGrouping = fieldGrouping;
	}
	public String getFieldType() {
		return fieldType;
	}
	public void setFieldType(String fieldType) {
		this.fieldType = fieldType;
	}

	public Map<String,String> getFieldListOfValueOptions() {
		return fieldListOfValueOptions;
	}
	public void setFieldListOfValueOptions(Map<String,String> fieldListOfValueOptions) {
		this.fieldListOfValueOptions = fieldListOfValueOptions;
	}
	
	public boolean isRequired() {
		return required;
	}
	public void setRequired(boolean required) {
		this.required = required;
	}
	public boolean isShowInSummaryTable() {
		return showInSummaryTable;
	}
	public void setShowInSummaryTable(boolean showInSummaryTable) {
		this.showInSummaryTable = showInSummaryTable;
	}
	public boolean isShowInDetailsPane() {
		return showInDetailsPane;
	}
	public void setShowInDetailsPane(boolean showInDetailsPane) {
		this.showInDetailsPane = showInDetailsPane;
	}
	public  List<String> getListOfAllTypes() {
		return listOfAllTypes;
	}
	public  void setListOfAllTypes(List<String> listOfAllTypes) {
		Field.listOfAllTypes = listOfAllTypes;
	}
	
	public  List<String> getListOfAllSources() {
		return listOfAllSources;
	}
	public  void setListOfAllSources(List<String> listOfAllSources) {
		Field.listOfAllSources = listOfAllSources;
	}
	public String getTempListOfValuesDelimited() {
		return tempListOfValuesDelimited;
	}
	public void setTempListOfValuesDelimited(String tempListOfValuesDelimited) 
	{
		if(tempListOfValuesDelimited == null)
		{
			fieldListOfValueOptions =  new  LinkedHashMap<String,String>();
			return;
		}
		
		this.tempListOfValuesDelimited = tempListOfValuesDelimited;
		StringTokenizer stk = new StringTokenizer(tempListOfValuesDelimited, System.getProperty("line.separator") );  
		this.fieldListOfValueOptions = new LinkedHashMap<String,String>();
		
		while ( stk.hasMoreTokens() ) 
		{  
			String current = stk.nextToken();
			
			if(current.indexOf(":") > -1)
			{
				String value = current.substring(0, current.indexOf(":"));
				String displayValue = current.substring(current.indexOf(":")+1);
				fieldListOfValueOptions.put(value, displayValue);
			}
			else
			{
				fieldListOfValueOptions.put(current,current);				
			}
		}  
	}
	
	public String toString()
	{
		return this.fieldGrouping + " : " + this.fieldName;
	}
	public boolean isSearchable() {
		return searchable;
	}
	public void setSearchable(boolean searchable) {
		this.searchable = searchable;
	}
	public boolean isFilterable() {
		return filterable;
	}
	public void setFilterable(boolean filterable) {
		this.filterable = filterable;
	}
	public boolean isSortable() {
		return sortable;
	}
	public void setSortable(boolean sortable) {
		this.sortable = sortable;
	}
	public String getFieldSource() {
		return fieldSource;
	}
	public void setFieldSource(String fieldSource) {
		this.fieldSource = fieldSource;
	}
	public String getFieldAutoOptionSelected() {
		return fieldAutoOptionSelected;
	}
	public void setFieldAutoOptionSelected(String fieldAutoOptionSelected) {
		this.fieldAutoOptionSelected = fieldAutoOptionSelected;
	}
	public  List<String> getListOfAllAutoOptions() {
		return listOfAllAutoOptions;
	}
	public  void setListOfAllAutoOptions(List<String> listOfAllAutoOptions) {
		Field.listOfAllAutoOptions = listOfAllAutoOptions;
	}
	public String getFieldExtractedDataPath() {
		return fieldExtractedDataPath;
	}
	public void setFieldExtractedDataPath(String fieldExtractedDataPath) {
		this.fieldExtractedDataPath = fieldExtractedDataPath;
	}
	public String getInputMask() {
		return inputMask;
	}
	public void setInputMask(String inputMask) {
		this.inputMask = inputMask;
	}
	
}
